home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / checklpt.arc / CHECKLPT.C next >
Encoding:
C/C++ Source or Header  |  1987-04-19  |  5.1 KB  |  97 lines

  1. /***************************************************************************/
  2. /*                                                                         */
  3. /* FILE_check_lpt_available . . . . Check if DOS printer is available,     */
  4. /*                                  starting with level 2 file pointer     */
  5. /* handle_check_lpt_available . . . Check if DOS printer is available,     */
  6. /*                                  starting with level 1 file handle.     */
  7. /*                                                                         */
  8. /* not_available = FILE_check_lpt_available(fp);                           */
  9. /* not_available = handle_check_lpt_available(handle);                     */
  10. /*                                                                         */
  11. /* int not_available;               1 if printer is not available,         */
  12. /*                                  0 if printer is available              */
  13. /* FILE *fp;                        File pointer                           */
  14. /* int handle;                      File handle                            */
  15. /*                                                                         */
  16. /*    These functions force an exit with error level 100 if they can not   */
  17. /* preempt or restore the DOS critical error handler.                      */
  18. /*    These functions require DOS 2.0 or later to run.  They rely on the   */
  19. /* calling program to check whether it is installed.                       */
  20. /*                                                                         */
  21. /*    I designed these functions for use with Lattice C, Version 3.  Some  */
  22. /* of their features which may not be portable are:                        */
  23. /*    fileno() is an UNIX function which returns the file handle for a     */
  24. /* file pointer.                                                           */
  25. /*    Lattice classes onerror(action) as a MSDOS function.  onerror(1)     */
  26. /* preeempts the MSDOS critical error handler.  onerror(0) restores the    */
  27. /* MSDOS critical error handler.                                           */
  28. /*    union REGS is a Lattice union which lets the registers become        */
  29. /* arguments to functions which invoke 8086 interrupts.  intdos is one     */
  30. /* such Lattice function which invokes interrupt 21H.                      */
  31. /*                                                                         */
  32. /*    Full identifiers in these functions conform to the proposed ANSI     */
  33. /* standard of at most 31 significant characters, and they are different   */
  34. /* within the first 8 characters.  Lattice C includes a -n compiler        */
  35. /* switch which changes the number of significant characters in            */
  36. /* identifiers from 8 to 39.  While these functions work without it, I     */
  37. /* designed them to use it.                                                */
  38. /*                                                                         */
  39. /* Lew Paper                                                               */
  40. /* 5/16/87                                                                 */
  41. /***************************************************************************/
  42.  
  43. #include <stdio.h>
  44. #include <dos.h>
  45. extern char _OSCEF;                 /* Lattice system variable.  Flag for  */
  46.                                     /* critical error.  A critical error   */
  47.                                     /* sets it to 3, and these functions   */
  48.                                     /* then resets it to 1.  If there is   */
  49.                                     /* no critical error, it is 0.         */
  50. extern short  _OSERR;               /* Lattice system variable.  Operating */
  51.                                     /* system error code.  83 for a        */
  52.                                     /* critical error.                     */
  53.  
  54. int FILE_check_lpt_available(fp)
  55.    FILE *fp;
  56.  
  57. {
  58.    return handle_check_lpt_available(fileno(fp));
  59. }
  60.  
  61. int handle_check_lpt_available(handle)
  62.    int handle;
  63.  
  64. {
  65.    union REGS reg;
  66.    int not_available;
  67.  
  68.    if (onerror(1))                     /* Preempt MSDOS critical error     */
  69.                                        /* handler.                         */
  70.    {
  71.       fputs("onerror(1) failed in handle_check_lpt_available\n\n", stderr);
  72.       exit(100);
  73.    }
  74.  
  75.    reg.x.ax = 0x4407;                  /* Check device output status       */
  76.    reg.x.bx = handle;
  77.    (void) intdos(®, ®);          
  78.    if (_OSCEF == 3)                    /* Critical error                   */
  79.    {
  80.       _OSCEF = 1;                      /* Lattice requires at least one    */
  81.                                        /* settings, and maybe both.        */
  82.       _OSERR = 83;
  83.       not_available = 1;
  84.    }
  85.    else
  86.       not_available = !reg.h.al;       /* AL = 0xff if the printer is      */
  87.                                        /* available or 0 if it is not      */
  88.    
  89.    if (onerror(0))                     /* Restore MSDOS critical error     */
  90.    {
  91.       fputs("onerror(0) failed in handle_check_lpt_available\n\n", stderr);
  92.       exit(100);
  93.    }
  94.  
  95.    return not_available;
  96. }
  97.